var DateRange = function(start, end) {
    this.start = Date.Min(start, end).clone();
    this.end = Date.Max(start, end).clone();
};

DateRange.prototype = {
    mergeWith: function(other) {
        var start = Date.Min(this.start, other.start);
        var end = Date.Max(this.end, other.end);
        return new DateRange(start, end);
    },

    hasOverlapWith: function(other) {
        return this.end > other.start && this.start < other.end;
    },

    containsDate: function(date) {
        return this.start.clone().clearTime() <= date && date <= this.end.clone().clearTime();
    },

    clearTime: function() {
        return new DateRange(this.start.clone().clearTime(), this.end.clone().clearTime());
    },

    toDayArray: function(){
        var array = [];
        for(var date= this.start; date <= this.end;date.addDays(1)){
             array.push(date.clone());
        }
        return array;
    }
};